#region Using References

using System;
using Beaker.OpenCube.Mapping;

#endregion

namespace Beaker.OpenCube.Game
{
	public sealed class UuidGuidConverter
		: IValueConverter
	{
		public object FromNbtToLocal( object nbtValue )
		{
			var array = nbtValue as object[];
			if( array != null && array.Length == 2 )
			{
				if( array[0] is long && array[1] is long )
				{
					byte[] highBytes = BitConverter.GetBytes( (long)array[0] );
					byte[] lowBytes = BitConverter.GetBytes( (long)array[1] );

					var localBytes = new byte[16]
					{
						highBytes[3], highBytes[2], highBytes[1], highBytes[0],
						highBytes[5], highBytes[4],
						highBytes[7], highBytes[6],
						lowBytes[1], lowBytes[0],
						lowBytes[2], lowBytes[3], lowBytes[4], lowBytes[5], lowBytes[6], lowBytes[7]
					};

					return new Guid( localBytes );
				}
			}

			throw new FormatException( "Failed to convert the nbt structure to a guid" );
		}

		public object FromLocalToNbt( object localValue, Type targetType )
		{
			throw new NotImplementedException();
		}
	}
}